import axios from 'axios'

export default {
  namespaced: true,
  state: {
    // token: localStorage.getItem('token') || ''
    token: '',
    userInfo: {},
    tokenFlag: 0
  },
  mutations: {
    updateToken (state, token) {
      // console.log(token)
      state.token = token

      // localStorage.setItem('token', token)
    },
    updataUserInfo (state, userInfo) {
      state.userInfo = userInfo
      // console.log(state.userInfo)
    },
    updateTokenFlag (state, tokenFlag) {
      state.tokenFlag = tokenFlag
    }
  },
  actions: {
    async getUserInfo (context) {
      // console.log(context)
      const { data: res } = await axios.get('/my/userinfo')
      console.log(res)
      if (res.code !== 0) return
      context.commit('updataUserInfo', res.data)
    }
  }
}
